<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="js/jquery.js"></script>
    <script>
        function f() {
            //提取出文件的二进制数据
            var fo=document.getElementById("up").files[0];
            var d=new FormData();
            d.append("file",fo);
            $.ajax({
                url:'/upload/up',
                type:'post',
                data:d,
                processData:false,//告诉jquery不要处理data,
                contentType:false,//告诉jquery不要设置内容类型
                success:function (data) {
                    $("img").attr("src",data);
                }
            });
        }
    </script>
</head>
<body>
    <form name="userform">
        <input type="file" name="file" id="up"><br>
        <img src="/imgs/ng.gif" style="height:300px;width:300px;"><br>
        <input type="button" value="提交" onclick="f();">
    </form>
</body>
</html>